<?
session_name('FROSTSESSID');
session_start();
/**
 * preflight
 */
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT']);
define('KERNEL', $_SERVER['DOCUMENT_ROOT']."/kernel");
define('MODULES', $_SERVER['DOCUMENT_ROOT']."/kernel/modules");
define('CONTROLLERS', $_SERVER['DOCUMENT_ROOT']."/kernel/controllers");
define('TEMPLATES', $_SERVER['DOCUMENT_ROOT']."/kernel/templates");

/**
 * Requires to startup modules
 */

$GLOBALS['MESS'] = array();

$arModules = array(
    'system.tools',
    'system.module',
    'system.buffer',
    'system.logger',
    'system.database',
    'system.main',
);

/**
 * Include startup modules
 */

foreach($arModules as $ns_module){
    list($ns, $module) = explode(".", $ns_module, 2);
    $filename = MODULES."/$ns/$module/".ucfirst($module).".module.php";
    
    if(!file_exists($filename)){
        print "<div>Module [$ns_module] not found</div>";
    }else{
        require_once $filename;
    }

}

if(!class_exists('Main')){
    die("Main module failed. Try later");
}

/**
 * If all ok, begin startup script
 */

include KERNEL."/init.php";

if(isset($addModules) && !empty($addModules) && class_exists('Module')){
    foreach($addModules as $ns_module){
        Module::Init($ns_module);
    }
}
include_once ROOT_DIR."/kernel/libs/php/lessphp/lessc.inc.php";
Buffer::Init();
$MAIN = new Main();
$USER = false;
$REQUEST = array();
if(class_exists('User')){
    $USER = new User();
}